import BasicLayout from "@/views/layout/index.vue"; // 基本布局
import BlankLayout from "@/views/layout/layout.vue"; // 空布局

import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
  {
    path: "/",
    name: "layout",
    redirect: "/home",
    meta: { title: "首页" },
    component: BasicLayout,
    children: [
      {
        path: "/home",
        name: "home",
        meta: { title: "首页" },
        component: () => import("@/views/home/index.vue"),
      },
      {
        path: "/account",
        name: "account",
        redirect: "/account/auth",
        meta: { title: "权限管理" },
        component: BlankLayout,
        children: [
          {
            path: "/account/auth",
            name: "auth",
            meta: { title: "菜单管理" },
            component: () => import("@/views/account/auth/index.vue"),
          },
          {
            path: "/account/role",
            name: "role",
            meta: { title: "角色管理" },
            component: () => import("@/views/account/role/index.vue"),
          },
          {
            path: "/account/admin",
            name: "admin",
            meta: { title: "账号管理" },
            component: () => import("@/views/account/admin/index.vue"),
          },
        ],
      },
      {
        path: "/system",
        name: "system",
        meta: { title: "设置" },
        component: BlankLayout,
        children: [
          {
            path: "/system/oss",
            name: "oss",
            meta: { title: "图片管理" },
            component: () => import("@/views/system/oss/index.vue"),
          },
          {
            path: "/system/setUp",
            name: "setUp",
            meta: { title: "系统设置" },
            component: () => import("@/views/system/setUp/index.vue"),
          },
          {
            path: "/system/adv",
            name: "adv",
            meta: { title: "广告管理" },
            component: () => import("@/views/system/adv/index.vue"),
          },
          {
            path: "/system/ship",
            name: "ship",
            meta: { title: "物流公司" },
            component: () => import("@/views/system/ship/index.vue"),
          },
          {
            path: "/system/addr",
            name: "addr",
            meta: { title: "售后地址" },
            component: () => import("@/views/system/addr/index.vue"),
          },
          {
            path: "/system/qa",
            name: "qa",
            meta: { title: "问答列表" },
            component: () => import("@/views/system/qa/index.vue"),
          },
        ],
      },
      {
        path: "/activity",
        name: "activity",
        meta: { title: "活动专区" },
        component: BlankLayout,
        children: [
          {
            path: "/activity/exchange",
            name: "exchangeList",
            meta: { title: "兑换/新人活动" },
            component: () => import("@/views/activity/exchange/index.vue"),
          },
          {
            path: "/activity/subscribe",
            name: "subscribeList",
            meta: { title: "申购活动" },
            component: () => import("@/views/activity/subscribe/index.vue"),
          },

          {
            path: "/activity/specialGoods",
            name: "specialGoods",
            meta: { title: "特价活动" },
            component: () => import("@/views/activity/specialGoods/index.vue"),
          },
          {
            path: "/activity/expansionGoods",
            name: "expansionGoods",
            meta: { title: "膨胀金活动" },
            component: () =>
              import("@/views/activity/expansionGoods/index.vue"),
          },
          {
            path: "/activity/newSubscribe",
            name: "newSubscribe",
            meta: { title: "申购活动(新)" },
            component: () => import("@/views/activity/newSubscribe/index.vue"),
          },
        ],
      },
      {
        path: "/order",
        name: "order",
        meta: { title: "订单管理" },
        component: BlankLayout,
        children: [
          {
            path: "/order/sale",
            name: "sale",
            meta: { title: "售后列表" },
            component: () => import("@/views/order/sale/index.vue"),
          },
          {
            path: "/order/list",
            name: "orderList",
            meta: { title: "订单列表" },
            component: () => import("@/views/order/list/index.vue"),
          },
          {
            path: "/order/energy",
            name: "orderEnergy",
            meta: { title: "能量订单" },
            component: () => import("@/views/order/energy/index.vue"),
          },
        ],
      },
      {
        path: "/user",
        name: "user",
        meta: { title: "用户管理" },
        component: BlankLayout,
        children: [
          {
            path: "/user/list",
            name: "userList",
            meta: { title: "用户列表" },
            component: () => import("@/views/user/list/index.vue"),
          },
          {
            path: "/user/verified",
            name: "verified",
            meta: { title: "实名认证" },
            component: () => import("@/views/user/verified/index.vue"),
          },
          {
            path: "/user/cash",
            name: "cashList",
            meta: { title: "提现列表" },
            component: () => import("@/views/user/cash/index.vue"),
          },
        ],
      },
      {
        path: "/notice",
        name: "notice",
        meta: { title: "公告管理" },
        component: BlankLayout,
        children: [
          {
            path: "/notice/list",
            name: "noticeList",
            meta: { title: "公告列表" },
            component: () => import("@/views/notice/list/index.vue"),
          },
        ],
      },
      {
        path: "/goods",
        name: "goods",
        meta: { title: "商品管理" },
        component: BlankLayout,
        children: [
          {
            path: "/goods/list",
            name: "goodsList",
            meta: { title: "商品列表" },
            component: () => import("@/views/goods/list/index.vue"),
          },
          {
            path: "/goods/label",
            name: "goodsLabel",
            meta: { title: "商品标签" },
            component: () => import("@/views/goods/label/index.vue"),
          },
          {
            path: "/goods/cate",
            name: "goodsCate",
            meta: { title: "商品分类" },
            component: () => import("@/views/goods/cate/index.vue"),
          },
          {
            path: "/goods/service",
            name: "goodsService",
            meta: { title: "商品服务" },
            component: () => import("@/views/goods/service/index.vue"),
          },
          {
            path: "/goods/newer",
            name: "goodsNewer",
            meta: { title: "新人活动" },
            component: () => import("@/views/goods/newer/index.vue"),
          },
        ],
      },
      {
        path: "/contact",
        name: "contact",
        meta: { title: "客户管理" },
        component: BlankLayout,
        children: [
          {
            path: "/contact/list",
            name: "contactList",
            meta: { title: "客服列表" },
            component: () => import("@/views/contact/list/index.vue"),
          },
          {
            path: "/contact/service",
            name: "contactService",
            meta: { title: "我的客户" },
            component: () => import("@/views/contact/service/index.vue"),
          },
        ],
      },
      {
        path: "/bd",
        name: "bd",
        meta: { title: "BD管理" },
        component: BlankLayout,
        children: [
          {
            path: "/bd/list",
            name: "bdList",
            meta: { title: "BD列表" },
            component: () => import("@/views/bd/list/index.vue"),
          },
          {
            path: "/bd/shop",
            name: "bdShop",
            meta: { title: "我的店铺" },
            component: () => import("@/views/bd/shop/index.vue"),
          },
        ],
      },
      {
        path: "/energy",
        name: "energy",
        meta: { title: "能量区间设置" },
        component: () => import("@/views/energy/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    meta: { title: "登录" },
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/errorPages/404.vue"),
    hidden: true,
  },
  {
    path: "/403",
    name: "403",
    component: () => import("@/views/errorPages/403.vue"),
    hidden: true,
  },
  {
    path: "/:pathMatch(.*)*",
    name: "not-found",
    redirect: "/404",
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes: routes,
});
router.resolve({
  name: "not-found",
  params: {
    pathMatch: ["not", "found"],
  },
}).href;

router.beforeEach((to, from, next) => {
  localStorage.setItem("path", to.path);
  next();
});

export default router;
